import loadable from '@loadable/component';
import {loadQuery, } from "react-relay/hooks";
import {Environment} from "relay-runtime";
import  PipeMainQuery  from "./__generated__/PipeMainQuery.graphql";
import {useContext} from "react";
import UserContext from "../routing/UserContext";
//import queryString from "querystring";
//import {PreloadableConcreteRequest} from "react-relay/relay-hooks/EntryPointTypes";
import  DetailedGuideQuery  from "./__generated__/PipeLineGuideQuery.graphql";
import  NewPipingUnitQuery  from "./__generated__/NewPipingUnitQuery.graphql";

const queryString = require('query-string');
/**
 * 管道单元的管理。
 * */
export default function secondRouter(environment: Environment) {
  return (
      {
        path: '/pipeline/:pId',
        //exact: true,  //多层路由嵌套只能去掉 true
        component: loadable(() => import('./PipeMain')),
        prepare: (params:any) => {
            let vars={
                pipe: params.pId,
                where: {proj: ''}, after:null, first:3,
            };
          return {
            myQuery: loadQuery(
                environment as any,
                PipeMainQuery as any,
                vars,
                { fetchPolicy: 'store-or-network' },
            )
          };
        },
        routes:[
            {
                path: '/pipeline/:pId/new',
                exact: true,
                component: loadable(() => import('./NewPipingUnit')),
                prepare: (params:any) => {
                    console.log(`路由历史NewPipingUnit点击路由params:`, params, window.history.state);
                    return {
                        myQuery: loadQuery(
                            environment as any,
                            NewPipingUnitQuery as any,
                            {
                                pipe: params.pId,
                            },
                            { fetchPolicy: 'store-or-network' },
                        ),
                    };
                },
            },
            {
                path: '/pipeline/:pId/:ppuId',
                exact: true,
                component: loadable(() => import('./PipeLineGuide')),
                prepare: (params:any) => {
                    console.log(`路由历史state7-点击路由params:`, params, window.history.state);
                    return {
                        eqpQuery: loadQuery(
                            environment as any,
                            DetailedGuideQuery as any,
                            {
                                id: params.ppuId,
                            },
                            { fetchPolicy: 'store-or-network' },
                        ),
                    };
                },
            },
        ],
      }
  );
}
